package com.projectfile.controller;



import com.projectfile.entity.LoginUser;
import com.projectfile.entity.User;
import com.projectfile.model.JsonResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;


import javax.annotation.Resource;

@RestController
public class FollowController {

    //notice的url
    public static final String NOTICE_URL="http://NOTICE-SERVICE";

    @Resource
    private RestTemplate restTemplate;
//登录
    @PostMapping(value="/toLogin")
    public JsonResult follow(@RequestBody LoginUser user){
        //操作数据
        //推送消息，调用另一个微服务
        return restTemplate.getForObject(NOTICE_URL+"/login/"+user.getUsername(), JsonResult.class);
    }
//存钱

    @PostMapping(value="/api/save")
    public JsonResult save(@RequestBody User user){
        //操作数据
        //推送消息，调用另一个微服务
        return restTemplate.getForObject(NOTICE_URL+"/save/"+user.getUserid()+"/"+user.getUser_money(), JsonResult.class);
    }

    //取钱

    @PostMapping(value="/api/withdraw")
    public JsonResult withdraw(@RequestBody User user){
        //操作数据
        //推送消息，调用另一个微服务
        System.out.println("ccccccccccccccccccccc");
        return restTemplate.getForObject(NOTICE_URL+"/withdraw/"+user.getUserid()+"/"+user.getUser_money(), JsonResult.class);
    }

    //余额
    @ResponseBody
    @PostMapping(value="/api/balance/{userid}")
    public JsonResult balance(@PathVariable String userid){
        //操作数据
        //推送消息，调用另一个微服务
        System.out.println("aaaaaaaaaaaa");
        return restTemplate.getForObject(NOTICE_URL+"/balance/"+userid, JsonResult.class);
    }

    //查询历史纪录
    @PostMapping(value="/api/history/{userid}")
    public JsonResult history(@PathVariable String userid){
        //操作数据
        //推送消息，调用另一个微服务
        System.out.println("bbbbbbbbbbbbbbbbbbb");
        return restTemplate.getForObject(NOTICE_URL+"/history/"+userid, JsonResult.class);
    }



}
